Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 120 - Stacks of flapjacks / 120.cpp
blobed3f92b687c6bbfd0ce50da3ba2b82b4c47d6631
1 /*
2 Problem: 120 - Stack of flapjacks
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 */
8 using namespace std;
9 #include <algorithm>
10 #include <iostream>
11 #include <iterator>
12 #include <sstream>
13 #include <fstream>
14 #include <cassert>
15 #include <climits>
16 #include <cstdlib>
17 #include <cstring>
18 #include <string>
19 #include <cstdio>
20 #include <vector>
21 #include <cmath>
22 #include <queue>
23 #include <deque>
24 #include <stack>
25 #include <map>
26 #include <set>
28 int main(){
30 string s;
31 while (getline(cin, s)){
32 stringstream sin(s);
34 vector<int> v, sol;
35 for (int x; sin >> x; v.push_back(x), sol.push_back(x));
36 sort(sol.begin(), sol.end(), greater<int>());
38 cout << v[0];
39 for (int i=1; i<v.size(); ++i) cout << " " << v[i];
40 cout << endl;
42 reverse(v.begin(), v.end());
44 int n = v.size();
46 int llevo = 0;
47 while (llevo < n){
48 int i=llevo;
49 while (v[i] != sol[llevo]) ++i;
50 if (i > llevo){
51 if (i+1 < n) cout << i+1 << " ";
52 reverse(v.begin()+i, v.end());
53 if (llevo+1 < n) cout << llevo+1 << " ";
54 reverse(v.begin()+llevo, v.end());
56 llevo++;
58 cout << "0\n";
60 return 0;